package com.jzy.message.activities.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jzy.message.R;
import com.jzy.message.activities.base.AppConfig;
import com.jzy.message.activities.base.AppRequestInterface;
import com.jzy.message.activities.base.BaseCommonAdapter;
import com.jzy.message.control.circleimageview.CircleImageView;
import com.jzy.message.util.image.ImageConfig;

import org.xutils.common.Callback;
import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/7/2.
 */
public class MessageContactAdapter<T> extends BaseCommonAdapter {
    public MessageContactAdapter(Context context, int layout_resource_id, List<T> adapter_data, int max_item_count)
    {
        super(context,layout_resource_id,adapter_data,max_item_count);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        RelativeLayout list_item_layout = (RelativeLayout) LayoutInflater.from(context).inflate(layout_resource_id, null);
        Map<String, Object> map = (Map<String, Object>)adapter_data.get(position);
        TextView tv_message_contact_name=(TextView)list_item_layout.findViewById(R.id.tv_message_contact_name);
        String sUserName=map.get("userName").toString();
        String sUserId=map.get("userId").toString();
        tv_message_contact_name.setText(sUserName);
        final CircleImageView cv_message_contact_avatarimage=(CircleImageView)list_item_layout.findViewById(R.id.cv_message_contact_avatarimage);
        String sImgUrl_AvatarImage = AppRequestInterface.getUserAvatarImageUrl(sUserId);//AppConfig.JsonUrl + map.get("AvatarImage").toString();
        cv_message_contact_avatarimage.setImageResource(R.drawable.temp_picpeople);
        x.image().loadDrawable(sImgUrl_AvatarImage, ImageConfig.image_options_default, new Callback.CommonCallback<Drawable>() {
            @Override
            public void onSuccess(Drawable drawable) {
                cv_message_contact_avatarimage.setImageDrawable(drawable);
            }
            @Override
            public void onError(Throwable throwable, boolean b) {

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
        return list_item_layout;
    }
}
